<?php
/****************************************************************************

	COPYRIGHT(C) WWW.MAXSI.DK, MAXSI SOFTWARE, SORTIE 2009
	ALL RIGHTS RESERVED

	Maxsi Distribution Achievements/ Branch
	Scripts shared by the MasterServer/ and ContentServer/ Branch of the Maxsi
	Distribution Server-Side Code Branches.
	
	showachievements.php
	Outputs a list of archievements per game!

****************************************************************************/

if ( !isset($_GET['product']) )
{
	echo '<p><b class="text_big">Achievements</b><br/>You forgot to specify what product!</p>';
}
else
{
	echo '<p><b class="text_big">Achievements for '.$_GET['product'].'</b><br /></p>';
	echo '<table>';
	
	$product_slot		=	md_sql('SELECT NumInstalled FROM md_products WHERE name = \''.md_SlashGlobalVar($_GET['product']).'\'');

	$num_total_users	=	$md_sql_row[$product_slot]['NumInstalled'];
	
	md_clearslot($product_slot);		

	$achievements		=	md_sql('SELECT ach.* as logoid FROM md_achievements ach, md_products p WHERE p.id = ach.product AND p.name = \''.md_SlashGlobalVar($_GET['product']).'\' ORDER BY ach.awarded DESC');
	
	for ( $I = 0; $I < $md_sql_total[$achievements]; $I++ )
	{
			echo '<tr><td>';
			echo '<table cellpadding="0" cellspacing="0" class="thumb100px"><tr><td><img src="addons/achievements/'.md_FileNameToHTTPURL(md_ProductNameToFileName($_GET['product'])).'_'.$md_sql_row[$achievements]['logoid'].'.png" alt="'.$md_sql_row[$achievements]['name'].'"/></td></tr></table>';
			echo '</td><td>';
			
			echo '<p><b class="text_big">'.$md_sql_row[$achievements]['name'].'</b><br />'.$md_sql_row[$achievements]['desc'].'<br />';
			
			if ( $num_total_users )
			{
				echo 'Unlocked by '.$md_sql_row[$achievements]['awarded'].' of '.$num_total_users.' users ('.(int)($md_sql_row[$achievements]['awarded']*100/$num_total_users).'%)</p>';
			}
			echo '</td></tr>';
			md_sql_next($achievements);
	}
	
	md_clearslot($achievements);	

	echo '</table>';
}
?>